package com.giscloud.minio.config;

import com.giscloud.commons.exception.BusinessException;
import io.minio.MinioClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname MinioConfig
 * @Description minio客户端配置
 * @Date 2020/6/24 11:11
 * @Created by gis
 */
@Log4j2
@Configuration
public class MinioConfig {
    @Autowired
    private MinioData minioData;

    /**
     * 初始化minio客户端,不用每次都初始化
     * @author 溪云阁
     * @return MinioClient
     */
    @Bean
    public MinioClient minioClient() {
        try {
            return new MinioClient(minioData.getUrl(), minioData.getAccessKey(), minioData.getSecretKey());
        }
        catch (final Exception e) {
            log.error("初始化minio出现异常:{}", e.fillInStackTrace());
            throw new BusinessException(e.fillInStackTrace());
        }
    }
}
